package com.shell.provider;

import com.shell.bee.base.utils.Encryptor;
import com.shell.bee.persistence.transaction.Transaction;
import com.shell.bee.persistence.transaction.TransactionUtil;
import com.shell.governor.modules.service.PubParameterService;
import com.shell.governor.modules.vo.ParameterVo;
import com.shell.governor.user.service.PubUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserPasswordUpateProvider {
	@Autowired
	private PubParameterService pubParameterService;
	@Autowired
	private PubUserService pubUserService;

	@RequestMapping({ "/user/updatePasswordExcludeAdmin" })
	public void updatePasswordExcludeAdmin() {
		TransactionUtil.execute(new Transaction() {
			public void doInTransaction() {
				String password = PasswordGenerator.gen();
				String md5 = Encryptor.encryptWithMD5(password);
				ParameterVo parameter = new ParameterVo();
				parameter.setParmCode("USER_PASSWORD");
				parameter.setParmValue(password);
				parameter.setParmRlatId("0");
				UserPasswordUpateProvider.this.pubParameterService.updateParam(parameter);
				UserPasswordUpateProvider.this.pubUserService.updatePasswordExcludeAdmin(md5);
			}
		}, new int[0]);
	}
}